<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <div>
        <el-form-item label="支付截止日期">
          <div class="block">
            <el-date-picker
              v-model="queryParams.startTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetime"
              clearable
              placeholder="选择日期时间">
            </el-date-picker>至
            <el-date-picker
              v-model="queryParams.endTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetime"
              placeholder="选择日期时间"
              clearable>
            </el-date-picker>
          </div>
        </el-form-item>
      </div>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:batch:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:batch:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:batch:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:batch:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="batchList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键 自增" align="center" prop="id" />
      <el-table-column label="账期年月日" align="center" prop="billDay" />
      <el-table-column label="对账年月日" align="center" prop="checkDay" />
      <el-table-column label="同一天内的批次序号" align="center" prop="batchNum" />
      <el-table-column label="批次号" align="center" prop="batchNo" />
      <el-table-column label="渠道名称" align="center" prop="billType" />
      <el-table-column label="平台支付订单笔数" align="center" prop="orderCount" />
      <el-table-column label="拉卡拉账单笔数" align="center" prop="checkCount" />
      <el-table-column label="差错账数量" align="center" prop="diffCount" />
      <el-table-column label="是否完成对账" align="center" prop="completeState" >
        <template slot-scope="scope">
          <span v-if="scope.row.completeState=='1'">完成</span>
          <span v-if="scope.row.completeState=='2'">未完成</span>
          <span v-if="scope.row.completeState=='3'">取消</span>
        </template>
      </el-table-column>
      <el-table-column label="对账确认时间" align="center" prop="confirmDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.confirmDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生成区分" align="center" prop="createType" >
        <template slot-scope="scope">
          <span v-if="scope.row.createType=='1'">自动</span>
          <span v-if="scope.row.createType=='2'">手动</span>
        </template>
      </el-table-column>
      <el-table-column label="账单下载批次" align="center" prop="downloadBatch" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="lookBatchDetail(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listBatch, getBatch, delBatch, addBatch, updateBatch } from "@/api/finance/batch";

export default {
  name: "Batch",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 对账批次表格数据
      batchList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {},
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询对账批次列表 */
    getList() {
      this.loading = true;
      listBatch(this.queryParams).then(response => {
        this.batchList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 详细按钮操作 */
    handleView(row) {
      this.open = true;
      this.form = row;
    },
    //查看详细信息
    lookBatchDetail(row){
      const id = row.batchNo;
      console.log(id);
      this.$router.push("/finance/detail/detail/"+id );
    }
  }
};
</script>
